//
//  ByApiRegistration.m
//  jinpuyiyuan_ios
//
//  Created by pro on 2017/12/18.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByApiRegistration.h"

#import "ByModelRegistrationSubject.h"

@implementation ByApiRegistration
// 分院科室查询
+ (void)getBranchOfficeList:(ByNetParamsModel *)model
                    success:(void(^)(ByNetBaseResult *result))success
                    failure:(void(^)(ByNetBaseResult *result))failure{
    static NSString *apiType = @"By_HospSect_query";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.hid forKey:@"hid"];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeArray
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"获取分院科室";
           NSMutableArray *tmp = [[NSMutableArray alloc] init];
           for (NSDictionary *dic in ((NSDictionary *)responseObject)) {
               ByModelRegistrationSubject *model = [[ByModelRegistrationSubject alloc] initContentWithDic:dic];
               [tmp addObject:model];
           }
           result.data = tmp;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           DLog(@"******** %@ 获取分院科室: %@", apiType, error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];

}
@end
